package com.wc.AlgoOJ_train.train1.c1.A108;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/12/26 10:17
 * 人见人爱A^B
 * http://43.138.190.70:8888/p/A108
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a == 0 && b == 0) {
                return;
            }
            System.out.println(quickMin(a, b));
        }
    }

    static int mod = 1000;

    static int quickMin(int a, int b) {
        int mul = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                mul = (mul * a) % mod;
            }
            a = a * a % mod;
            b >>= 1;
        }
        return mul;
    }
}
